package cn.datawin.dockerclient.service.impl;

import cn.datawin.bms.deploy.entity.DeplDockerInfoEntity;
import cn.datawin.dockerclient.mapper.DeplDockerInfoMapper;
import cn.datawin.dockerclient.service.DeplDockerInfoService;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * docker容器表
 *
 * @author shengdongcloud
 * @date 2025-03-13 09:53:03
 */
@Service
public class DeplDockerInfoServiceImpl extends ServiceImpl<DeplDockerInfoMapper, DeplDockerInfoEntity> implements DeplDockerInfoService {

	@Override
	public void updateStatusById(int id, int status){
		//更新docker_info表，id为容器id，status为容器状态
		//更新容器id的状态
		DeplDockerInfoEntity entity = new DeplDockerInfoEntity();
		entity.setId(id);
		entity.setStatus(status);
		entity.setUpdatetime(LocalDateTime.now());
		this.baseMapper.updateById(entity);
	}

	@Override
	public long countByContainerName(String container_name, String server_ip) {

		QueryWrapper<DeplDockerInfoEntity> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("container_name",container_name);
		queryWrapper.eq("server_ip",server_ip);
		queryWrapper.in("status", CollUtil.newArrayList(0,1));
		return this.baseMapper.selectCount(queryWrapper);
	}
}
